package com.ceair.flight.refund.dto.appmoblie;

import com.ceair.flight.refund.location.dt.enums.RefundTktNature;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

public class RefundTktDto implements Serializable {

    private static final long serialVersionUID = -739727538222962727L;

    private long id;
    private RefundApplyDto refundApply;
    private String ticketNo;
    private String applyNo;
    private String refTktNo;
    private Long paxId;
    private String paxName;
    private String paxType;
    private String paxPhone;
    private String paxEmail;
    private String notifyPax;
    private String ticketType;
    private String pnrNo;
    private String refundPnrNo;
    private String refundTicketNo;
    private String orderNo;
    private String flightOrderNo;
    private String channelNo;
    private String tktNature;
    private String paymentChannelCode;
    private BigDecimal refundFee;
    //不含税应退金额
    private BigDecimal refundAmt;
    //应退税额
    private BigDecimal refundTax;
    private String refundStatus;
    //销售价
    private BigDecimal tktAmt;
    //票面价
    private BigDecimal tktPrice;
    private BigDecimal leftTktPrice;
    private BigDecimal rescheduleGap;
    private BigDecimal refundResGap;//退还的改期差额
    private BigDecimal rescheduleFee;
    private BigDecimal rescheduleFeeRes;//实际的改期手续费
    private BigDecimal rescheduleTax;
    //促销优惠金额
    private BigDecimal promoteAmt;
    private Long tktPoints;
    private Long refundPoints;
    private Set<RefundTaxDto> refundTaxes = new HashSet<>(0);
    private Set<RefundSegDto> refundSegs = new HashSet<>(0);
    private Set<RefundAdditionalDto> refundAdditionals = new HashSet<>(0);
    private String currency;

    //获取含税应退金额
    public BigDecimal getTotalRefundAmt() {
        BigDecimal tmpRefundAmt = BigDecimal.ZERO;
        if (refundAmt != null) {
            tmpRefundAmt = refundAmt;
        }
        BigDecimal tmpRefundTax = BigDecimal.ZERO;
        if (refundTax != null) {
            tmpRefundTax = refundTax;
        }
        return tmpRefundAmt.add(tmpRefundTax);
    }

    private RefundSegDto getFirstSeg() {
        return refundSegs.iterator().next();
    }

    public List<RefundSegDto> getSortSegs() {
        List<RefundSegDto> sortRefundSegs = new ArrayList<>(refundSegs);
        Collections.sort(sortRefundSegs);
        return sortRefundSegs;
    }

    public boolean isPartailRefund() {
        List<RefundSegDto> refundedSegs = getSortSegs();
        RefundSegDto firstRefundSeg = refundedSegs.get(0);
        return firstRefundSeg.getIndexNo() > 1;
    }

    //获取第一段退改规则, 国际航线票使用
    public String getRefundRule() {
        return getFirstSeg().getRefundRule();
    }

    //获取第一段退改规则, 国际航线票使用
    public String getRealRefundRule() {
        return getFirstSeg().getRealRefundRule();
    }

    //获取第一段退改规则, 国际航线票使用
    public String getEiContent() {
        return getFirstSeg().getEiContent();
    }

    /**
     *
     * 计算实际支付金额, 由于支付表没有具体的每张票支付了多少金额, 所以这里只能再计算一次
     *
     * 实际支付金额为 销售价 - 促销优惠金额(如果有)
     *
     * @return
     */
//    public String getPayAmt() {
//        if (this.promoteAmt != null && (tktPoints == null || tktPoints == 0)) {
//            return (this.tktAmt.subtract(this.promoteAmt)).toString();
//        }
//        return this.tktAmt.toString();
//    }
    public long getId() {
        return id;
    }

    public void setId(long id) {
        this.id = id;
    }

    public RefundApplyDto getRefundApply() {
        return refundApply;
    }

    public void setRefundApply(RefundApplyDto refundApply) {
        this.refundApply = refundApply;
    }

    public String getApplyNo() {
        return applyNo;
    }

    public void setApplyNo(String applyNo) {
        this.applyNo = applyNo;
    }

    public String getTicketNo() {
        return ticketNo;
    }

    public void setTicketNo(String ticketNo) {
        this.ticketNo = ticketNo;
    }

    public Long getPaxId() {
        return paxId;
    }

    public void setPaxId(Long paxId) {
        this.paxId = paxId;
    }

    public String getPaxName() {
        return paxName;
    }

    public void setPaxName(String paxName) {
        this.paxName = paxName;
    }

    public String getPaxType() {
        return paxType;
    }

    public void setPaxType(String paxType) {
        this.paxType = paxType;
    }

    public String getPaxPhone() {
        return paxPhone;
    }

    public void setPaxPhone(String paxPhone) {
        this.paxPhone = paxPhone;
    }

    public String getPaxEmail() {
        return paxEmail;
    }

    public void setPaxEmail(String paxEmail) {
        this.paxEmail = paxEmail;
    }

    public String getNotifyPax() {
        return notifyPax;
    }

    public void setNotifyPax(String notifyPax) {
        this.notifyPax = notifyPax;
    }

    public String getTicketType() {
        return ticketType;
    }

    public void setTicketType(String ticketType) {
        this.ticketType = ticketType;
    }

    public boolean isInterAirline() {
        return "I".equals(ticketType);
    }

    public boolean isDomesticAirline() {
        return "D".equals(ticketType);
    }

    public String getPnrNo() {
        return pnrNo;
    }

    public void setPnrNo(String pnrNo) {
        this.pnrNo = pnrNo;
    }

    public String getRefundPnrNo() {
        return refundPnrNo;
    }

    public void setRefundPnrNo(String refundPnrNo) {
        this.refundPnrNo = refundPnrNo;
    }

    public String getRefundTicketNo() {
        return refundTicketNo;
    }

    public void setRefundTicketNo(String refundTicketNo) {
        this.refundTicketNo = refundTicketNo;
    }

    public String getOrderNo() {
        return orderNo;
    }

    public void setOrderNo(String orderNo) {
        this.orderNo = orderNo;
    }

    public String getFlightOrderNo() {
        return flightOrderNo;
    }

    public void setFlightOrderNo(String flightOrderNo) {
        this.flightOrderNo = flightOrderNo;
    }

    public String getChannelNo() {
        return channelNo;
    }

    public void setChannelNo(String channelNo) {
        this.channelNo = channelNo;
    }

    public Set<RefundTaxDto> getRefundTaxes() {
        return refundTaxes;
    }

    public void setRefundTaxes(Set<RefundTaxDto> refundTaxes) {
        this.refundTaxes = refundTaxes;
    }

    public Set<RefundSegDto> getRefundSegs() {
        return refundSegs;
    }

    public void setRefundSegs(Set<RefundSegDto> refundSegs) {
        this.refundSegs = refundSegs;
    }

    public String getRefTktNo() {
        return refTktNo;
    }

    public void setRefTktNo(String refTktNo) {
        this.refTktNo = refTktNo;
    }

    public String getTktNature() {
        return tktNature;
    }

    public void setTktNature(String tktNature) {
        this.tktNature = tktNature;
    }

    public String getPaymentChannelCode() {
        return paymentChannelCode;
    }

    public void setPaymentChannelCode(String paymentChannelCode) {
        this.paymentChannelCode = paymentChannelCode;
    }

    public BigDecimal getRefundFee() {
        return refundFee;
    }

    public void setRefundFee(BigDecimal refundFee) {
        this.refundFee = refundFee;
    }

    public BigDecimal getRefundAmt() {
        return refundAmt;
    }

    public void setRefundAmt(BigDecimal refundAmt) {
        this.refundAmt = refundAmt;
    }

    public BigDecimal getRefundTax() {
        return refundTax;
    }

    public void setRefundTax(BigDecimal refundTax) {
        this.refundTax = refundTax;
    }

    public String getRefundStatus() {
        return refundStatus;
    }

    public void setRefundStatus(String refundStatus) {
        this.refundStatus = refundStatus;
    }

    public BigDecimal getTktAmt() {
        return tktAmt;
    }

    public void setTktAmt(BigDecimal tktAmt) {
        this.tktAmt = tktAmt;
    }

    public BigDecimal getTktPrice() {
        return tktPrice;
    }

    public void setTktPrice(BigDecimal tktPrice) {
        this.tktPrice = tktPrice;
    }

    public BigDecimal getLeftTktPrice() {
        return leftTktPrice;
    }

    public void setLeftTktPrice(BigDecimal leftTktPrice) {
        this.leftTktPrice = leftTktPrice;
    }

    public BigDecimal getRescheduleGap() {
        return rescheduleGap;
    }

    public void setRescheduleGap(BigDecimal rescheduleGap) {
        this.rescheduleGap = rescheduleGap;
    }

    public BigDecimal getRefundResGap() {
        return refundResGap;
    }

    public void setRefundResGap(BigDecimal refundResGap) {
        this.refundResGap = refundResGap;
    }

    public BigDecimal getRescheduleFee() {
        return rescheduleFee;
    }

    public void setRescheduleFee(BigDecimal rescheduleFee) {
        this.rescheduleFee = rescheduleFee;
    }

    public BigDecimal getRescheduleTax() {
        return rescheduleTax;
    }

    public void setRescheduleTax(BigDecimal rescheduleTax) {
        this.rescheduleTax = rescheduleTax;
    }

    public BigDecimal getPromoteAmt() {
        return promoteAmt;
    }

    public void setPromoteAmt(BigDecimal promoteAmt) {
        this.promoteAmt = promoteAmt;
    }

    public Long getTktPoints() {
        return tktPoints;
    }

    public void setTktPoints(Long tktPoints) {
        this.tktPoints = tktPoints;
    }

    public Long getRefundPoints() {
        return refundPoints;
    }

    public void setRefundPoints(Long refundPoints) {
        this.refundPoints = refundPoints;
    }

    public Set<RefundAdditionalDto> getRefundAdditionals() {
        return refundAdditionals;
    }

    public void setRefundAdditionals(Set<RefundAdditionalDto> refundAdditionals) {
        this.refundAdditionals = refundAdditionals;
    }

	public BigDecimal getRescheduleFeeRes() {
		return rescheduleFeeRes;
	}

	public void setRescheduleFeeRes(BigDecimal rescheduleFeeRes) {
		this.rescheduleFeeRes = rescheduleFeeRes;
	}

    public boolean isReschedule() {
        if (tktNature == null) {
            return false;
        }
        return RefundTktNature.RESCHEDULE == RefundTktNature.getByCode(tktNature);
    }

    public String getCurrency() {
        return currency;
    }

    public void setCurrency(String currency) {
        this.currency = currency;
    }
}
